import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [
  {
    path: '/',
    component: () => import('@/views/login/index'),
    hidden: true,
  },

  // {
  //   path: '/404',
  //   component: () => import('@/views/404'),
  //   hidden: true
  // },

  

  // 404 page must be placed at the end !!!
  //{ path: '*', redirect: '/404', hidden: true }
]

// 异步加载的路由
export const asynRouter = [
  {
    path: '/main',
    component: Layout,
    redirect: '/main',
    meta: { title: '预览', icon: 'home', menuNo: 101 },
    children: [
      {
        path: 'index',
        name: 'index',
        component: () => import('@/views/main/index'),
        meta: {
          title: '业务预览',
          icon: 'dashboard',
          menuNo: 20101,
          parentId: 101,
        },
      },
      {
        path: '/main/sale',
        name: 'salePreview',
        component: () => import('@/views/main/sale'),
        meta: {
          title: '销售预览',
          icon: 'dashboard',
          menuNo: 20102,
          parentId: 101,
        },
      },
      {
        path: '/main/hospital',
        name: 'hospitalPreview',
        component: () => import('@/views/main/hospital'),
        meta: {
          title: '医院预览',
          icon: 'dashboard',
          menuNo: 20103,
          parentId: 101,
        },
      },
    ],
  },
  {
    path: '/customer',
    component: Layout,
    name: 'customer',
    meta: { title: '客户', icon: 'customer', menuNo: 301 },
    children: [
      {
        path: '/customer/index',
        name: 'customerAll',
        component: () => import('@/views/customer/index'),
        meta: {
          title: '所有客户',
          icon: 'table',
          menuNo: 30101,
          parentId: 301,
        },
      },
      {
        path: '/customer/contact',
        name: 'customerContact',
        component: () => import('@/views/customer/contact'),
        meta: {
          title: '待联系客户',
          icon: 'tree',
          menuNo: 30102,
          parentId: 301,
        },
      },
      {
        path: '/customer/book',
        name: 'customerBook',
        component: () => import('@/views/customer/book'),
        meta: {
          title: '待预约客户',
          icon: 'tree',
          menuNo: 30103,
          parentId: 301,
        },
      },
      {
        path: '/customer/booked',
        name: 'customerBooked',
        component: () => import('@/views/customer/booked'),
        meta: {
          title: '已预约客户',
          icon: 'tree',
          menuNo: 30104,
          parentId: 301,
        },
      },
      {
        path: '/customer/traded',
        name: 'customerTraded',
        component: () => import('@/views/customer/traded'),
        meta: {
          title: '已成交客户',
          icon: 'tree',
          menuNo: 30105,
          parentId: 301,
        },
      },
      {
        path: '/customer/unsettled',
        name: 'customerUnsettled',
        component: () => import('@/views/customer/unsettled'),
        meta: {
          title: '未成交客户',
          icon: 'tree',
          menuNo: 30106,
          parentId: 301,
        },
      },
    ],
  },
  {
    path: '/book',
    component: Layout,
    name: 'book',
    meta: { title: '预约', icon: 'book', menuNo: 401 },
    children: [
      {
        path: '/book/index',
        name: 'bookIndex',
        component: () => import('@/views/book/index'),
        meta: { title: '所有预约', icon: 'form', menuNo: 40101, parentId: 401 },
      },
      {
        path: '/book/undue',
        name: 'bookUndue',
        component: () => import('@/views/book/undue'),
        meta: { title: '未到期', icon: 'form', menuNo: 40102, parentId: 401 },
      },
      {
        path: '/book/expired',
        name: 'bookeExpired',
        component: () => import('@/views/book/expired'),
        meta: { title: '已到期', icon: 'form', menuNo: 40103, parentId: 401 },
      },
      {
        path: '/book/visit',
        name: 'bookVisit',
        component: () => import('@/views/book/visit'),
        meta: { title: '待回访', icon: 'form', menuNo: 40104, parentId: 401 },
      },
    ],
  },
  {
    path: '/deal',
    component: Layout,
    meta: { title: '成交', icon: 'deal', menuNo: 501, parentId: 501 },
    children: [
      {
        path: '/deal/record',
        name: 'dealRecord',
        component: () => import('@/views/deal/index'),
        meta: { title: '成交记录', icon: 'form', menuNo: 50101, parentId: 501 },
      },
      {
        path: '/deal/payment',
        name: 'dealPayment',
        component: () => import('@/views/deal/payment'),
        meta: { title: '收款记录', icon: 'form', menuNo: 50102, parentId: 501 },
      },
      {
        path: '/deal/results',
        name: 'dealResults',
        component: () => import('@/views/deal/results'),
        meta: { title: '业绩核算', icon: 'form', menuNo: 50103, parentId: 501 },
      },
    ],
  },
  {
    path: '/scheduling',
    component: Layout,
    name: 'scheduling',
    meta: { title: '排班', icon: 'scheduling', menuNo: 601 },
    children: [
      {
        path: '/scheduling/index',
        name: 'schedulingIndex',
        component: () => import('@/views/scheduling/index'),
        meta: { title: '排班', icon: 'form', menuNo: 60101, parentId: 601 },
      },
    ],
  },
  {
    path: '/hospital',
    component: Layout,
    name: 'hospital',
    meta: { title: '医院', icon: 'hospital', menuNo: 701 },
    // component:() => import('@/views/information/index'),
    children: [
      {
        path: '/hospital/index',
        name: 'hospital',
        component: () => import('@/views/hospital/index'),
        redirect: '/hospital/list',
        meta: { title: '医院信息', icon: 'form', menuNo: 70101, parentId: 701 },
        children: [
          {
            path: '/hospital/list',
            name: 'hospital',
            component: () => import('@/views/hospital/list'),
            //redirect: '/hospital/list',
            meta: {
              title: '医院信息',
              icon: 'form',
              menuNo: 70101,
              parentId: 701,
            },
          },
          {
            path: '/hospital/add',
            name: 'addHospital',
            hidden: true,
            component: () => import('@/views/hospital/add'),
            meta: {
              title: '新增医院',
              icon: 'form',
              menuNo: 70102,
              level: 3,
            },
          },
        ],
      },

      {
        path: '/doctor',
        name: 'hospitalDoctorIndex',
        component: () => import('@/views/doctor/index'),
        redirect: '/doctor/list',
        meta: { title: '医生信息', icon: 'form', menuNo: 70103, parentId: 701 },
        children: [
          {
            path: '/doctor/list',
            name: 'hospitalDoctor',
            component: () => import('@/views/doctor/list'),
            meta: {
              title: '医生信息',
              icon: 'form',
              menuNo: 70103,
              parentId: 701,
            },
          },
          {
            path: '/doctor/add',
            name: 'addDoctor',
            hidden: true,
            component: () => import('@/views/doctor/add'),
            meta: {
              title: '新增医生',
              icon: 'form',
              menuNo: 70104,
              level: 3,
            },
          },
        ],
      },
    ],
  },
  {
    path: '/statistics',
    component: Layout,
    name: 'statistics',
    meta: { title: '数据', icon: 'data', menuNo: 801 },
    children: [
      {
        path: '/statistics/index',
        name: 'hospitalStatistics',
        component: () => import('@/views/statistics/index'),
        meta: { title: '医院统计', icon: 'form', menuNo: 80101, parentId: 801 },
      },
      {
        path: '/statistics/sale',
        name: 'saleStatistics',
        component: () => import('@/views/statistics/sale'),
        meta: { title: '销售统计', icon: 'form', menuNo: 80102, parentId: 801 },
      },
      {
        path: '/statistics/ad',
        name: 'adStatistics',
        component: () => import('@/views/statistics/ad'),
        meta: { title: '广告统计', icon: 'form', menuNo: 80103, parentId: 801 },
      },
    ],
  },
  {
    path: '/system',
    component: Layout,
    meta: { title: '系统', icon: 'system', menuNo: 101 },
    children: [
      {
        path: '/system/todo',
        name: 'system.todo',
        component: () => import('@/views/system/todo'),
        meta: {
          title: '待办通知',
          icon: 'el-icon-user',
          menuNo: 10104,
          parentId: 101,
        },
      },
      {
        path: '/system/visitRecord',
        name: 'system.visitRecord',
        component: () => import('@/views/system/visitRecord'),
        meta: {
          title: '回访记录',
          icon: 'el-icon-user',
          menuNo: 10105,
          parentId: 101,
        },
      },
      {
        path: '/system/message',
        name: 'system.message',
        component: () => import('@/views/system/msg'),
        meta: {
          title: '短信记录',
          icon: 'el-icon-user',
          menuNo: 10106,
          parentId: 101,
        },
      },
      {
        path: '/system/source',
        name: 'system.source',
        component: () => import('@/views/system/source'),
        meta: {
          title: '来源配置',
          icon: 'el-icon-user',
          menuNo: 10107,
          parentId: 101,
        },
      },
      {
        path: '/system/ad',
        name: 'system.ad',
        component: () => import('@/views/system/ad'),
        meta: {
          title: '广告代号',
          icon: 'el-icon-user',
          menuNo: 10108,
          parentId: 101,
        },
      },
      {
        path: '/system/project',
        name: 'system.project',
        component: () => import('@/views/system/project'),
        meta: {
          title: '项目配置',
          icon: 'el-icon-user',
          menuNo: 10109,
          parentId: 101,
        },
      },
      {
        path: '/system/city',
        name: 'system.city',
        component: () => import('@/views/system/city'),
        meta: {
          title: '城市配置',
          icon: 'el-icon-user',
          menuNo: 10110,
          parentId: 101,
        },
      },
      {
        path: '/system/user',
        name: 'systemuser',
        component: () => import('@/views/system/user'),
        meta: {
          title: '用户管理',
          icon: 'el-icon-user',
          menuNo: 10101,
          parentId: 101,
        },
      },
      {
        path: '/system/department',
        name: 'department',
        component: () => import('@/views/system/department'),
        meta: {
          title: '部门管理',
          icon: 'el-icon-office-building',
          menuNo: 10102,
          parentId: 101,
        },
      },
      {
        path: '/system/menu',
        name: 'menu',
        component: () => import('@/views/system/menu'),
        meta: {
          title: '菜单管理',
          icon: 'el-icon-connection',
          menuNo: 10103,
          parentId: 101,
        },
      },
      // {
      //   path: 'permissions',
      //   name: 'permissions',
      //   component: () => import('@/views/system/permissions'),
      //   meta: { title: '权限管理', icon: 'el-icon-connection', menuNo: 10104 }
      // },
      {
        path: '/system/role',
        name: 'role',
        component: () => import('@/views/system/role'),
        meta: { title: '角色管理', icon: 'form', menuNo: 10105, parentId: 101 },
      },
    ],
  },
  { path: '*', redirect: '/404', hidden: true },
]

const createRouter = () =>
  new Router({
    // mode: 'history', // require service support
    scrollBehavior: () => ({ y: 0 }),
    routes: constantRoutes,
  })

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
